// pages/shebei/shebei.js
// 链接mqtt.js文件
const app = getApp();

Page({
    /**
     * 页面的初始数据
     */
    data: {
        toplink: {},
        datashow: [{
                id: "紫外线强度",
                datadh: "zyd",
                icon: "https://6d79-mybiyesheji-1g9dugc1e05b04c4-1309023553.tcb.qcloud.la/icon/%E7%B4%AB%E5%A4%96%E7%BA%BF%E5%BC%BA.png?sign=98f2eed449fc55b5fb7d2c712188ab13&t=1669722093",
                data: "uv：10"
            },
            {
                id: "有毒气体浓度",
                datadh: "yyd",
                icon: "https://6d79-mybiyesheji-1g9dugc1e05b04c4-1309023553.tcb.qcloud.la/icon/%E4%BA%8C%E6%B0%A7%E5%8C%96%E7%A2%B3%E6%B5%93%E5%BA%A6.png?sign=27ea65d373d72989828ef9f04c1ada7a&t=1669722105",
                data: ""
            },
            {
                id: "大气温度",
                datadh: "zyd",
                icon: "https://6d79-mybiyesheji-1g9dugc1e05b04c4-1309023553.tcb.qcloud.la/icon/%E6%B8%A9%E5%BA%A6%E8%AE%A1.png?sign=32f616ca1f0690858f57dbf9018c8458&t=1669722120",
                data: "32°c"
            },
            {
                id: "气压等式海拔",
                datadh: "yyd",
                icon: "https://6d79-mybiyesheji-1g9dugc1e05b04c4-1309023553.tcb.qcloud.la/icon/%E6%B5%B7%E6%8B%94.png?sign=e623e08c829a16b0618077ca98fe0290&t=1669722153",
                data: "35 米"
            },
            {
                id: "大气压强",
                datadh: "zyd",
                icon: "https://6d79-mybiyesheji-1g9dugc1e05b04c4-1309023553.tcb.qcloud.la/icon/%E6%B0%94%E5%8E%8B.png?sign=ae2cfbd4b864a888fe98939e04c675a5&t=1669722166",
                data: "1009 bpa"
            },
            {
                id: "头盔设备定位",
                icon: "https://6d79-mybiyesheji-1g9dugc1e05b04c4-1309023553.tcb.qcloud.la/icon/%E5%AE%9A%E4%BD%8D.png?sign=ac077b79044f1c6d1f6c97421fa5934d&t=1669722183",
                data: "头盔定位信息",
                tp:'runtuabout'
            }

        ],
        zyd: {},
        yzd: {},
        hr: 65,
        spo2: 90.63251,
        temp: 20,
        hb: 35,
        qy: 101.633,
        co:0,
        flag:"在线",
        hricon: "https://6d79-mybiyesheji-1g9dugc1e05b04c4-1309023553.tcb.qcloud.la/icon/%E5%BF%83%E7%8E%87.png?sign=b5612770f5352195edbb76155c8e0c63&t=1669722199",
        spo2icon: "https://6d79-mybiyesheji-1g9dugc1e05b04c4-1309023553.tcb.qcloud.la/icon/%E8%A1%80%E6%B0%A7.png?sign=eb5c0ad92320fb4749472a4f053433cb&t=1669722212",
        /*定时器获取MQTT数据 */
        inter: '',
    },
    startInter: function () {
        var that = this;
        that.data.inter = setInterval(
            function () {
                 console.log(app.globalData.mqttJSON)
                if (app.globalData.mqttJSON.hr != 0) {
                    that.setData({
                        hr: app.globalData.mqttJSON.hr
                    })
                }


                if (app.globalData.mqttJSON.hr != 0) {
                    that.setData({
                        spo2: ((app.globalData.mqttJSON.hr/10) * 0.68 + 91).toFixed(2)
                    })
                }
                else 
                {
                        that.setData({
                                spo2: "wait.."
                            })    
                }
                if (app.globalData.mqttJSON.hb > 0) {
                        that.setData({
                                hb: app.globalData.mqttJSON.hb.toFixed(2)
                            })   
                }
                else
                {
                        that.setData({
                                
                                hb:Math.abs(app.globalData.mqttJSON.hb).toFixed(2)
                            })   
                }
                that.setData({
                    temp : app.globalData.mqttJSON.tp/10,
                    qy: app.globalData.mqttJSON.qy/1000,
                    co: app.globalData.mqttJSON.co
                })
                    
            }, 50);
    },
    endInter: function () {
        var that = this;
        that.clearInterval(that.data.inter)
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        console.log(app.globalData.mqttJSON)
        this.toplink = wx.createAnimation({
            duration: 400,
            timingFunction: 'ease-in-out'
        })

        this.zyd = wx.createAnimation({
            duration: 400,
            timingFunction: 'ease-in-out'
        })

        this.yyd = wx.createAnimation({
            duration: 300,
            timingFunction: 'ease-in-out'
        })          
},
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {
        this.startInter();
        /**左运动 */
        this.zyd.translateX(0).step()
        this.zyd.translateX(-50).step()
        this.zyd.translateX(0).step()
        /**右运动 */
        this.yyd.translateX(0).step()
        this.yyd.translateX(50).step()
        this.yyd.translateX(0).step()
        /**创建 菜单的动画实例 */
        this.toplink.translateY(0).step()
        this.toplink.translateY(50).step()
        this.toplink.translateY(0).step()

        this.setData({
            toplink: this.toplink.export(),
            zyd: this.zyd.export(),
            yyd: this.yyd.export()
        }) 
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {
    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {
       clearInterval(this.data.inter)
    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {
    },

    jumphrdata() {

        wx.navigateTo({
            url: '/pages/hrdata/hrdata',
        })
    },
    runtuabout(){
            clearInterval(this.data.inter)
            wx.navigateTo({
              url: '/pages/about/about',
            })
    }
})